package com.ztc.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.ztc.bean.ReportHistoryModel;

@Mapper
public interface ReportHistoryDao {
	
//	@Select("select count(1) num from tab_apply_info where projectId=#{projectId} and applyType=2")
//	public Map<String, Object> queryApprovalInfo(@Param("projectId") int projectId);
//	
//	@Select("select * from tab_approval_file where projectId=#{projectId} order by updateTime desc limit 1")
//	public Map<String, Object> queryApprovalVersion(@Param("projectId") int projectId);
	
	@Select("select count(1) num from tab_approval_receipt where projectId=#{projectId}")
	public Map<String, Object> queryApprovalInfo(@Param("projectId") int projectId);
	
	@Select("select * from tab_approval_files where projectId=#{projectId} and type=1 order by updateTime desc limit 1")
	public Map<String, Object> queryApprovalVersion(@Param("projectId") int projectId);
	
	@Select("select * from tab_report_history where tableId=#{relation} and projectId=#{projectId} order by updateTime desc")
	public List<ReportHistoryModel> queryHistoryList(@Param("relation") String relation, @Param("projectId") int projectId);

	@Insert("INSERT INTO tab_report_history (projectId, tableId, content, approvalVersion, version, enterpriseId)"
			+ " VALUES (#{reportHistory.projectId}, #{reportHistory.tableId}, #{reportHistory.content},"
			+ " #{reportHistory.approvalVersion}, #{reportHistory.version}, #{reportHistory.enterpriseId})")
	public int addReportHistory(@Param("reportHistory") ReportHistoryModel reportHistory);
	
	@Select("select * from tab_report_history where tableId=#{relation} and projectId=#{projectId} and version=#{version} order by updateTime desc limit 1")
	public ReportHistoryModel queryReportHistory(@Param("relation") String relation, @Param("projectId") int projectId, @Param("version") String version);
}
